import tinymce from 'tinymce/tinymce'
import { docExport } from '@/api'
import { saveBeforeExport } from '@/utils/helpers'
import store from '@/store'

tinymce.PluginManager.add('docExport', function (editor) {
  editor.ui.registry.addNestedMenuItem('docExport', {
    text: '导出',
    getSubmenuItems: function () {
      const menu = store.state.xmleditor.permissions?.menu?.docExport || []
      return menu.map((type) => {
        return {
          type: 'menuitem', text: type, async onAction() {
            // await saveBeforeExport()
            docExport(type)
          }
        }
      })
    }
  })

  return {
    getMetadata: function () {
      return {
        name: '导出',
        url: 'http://sfrj.cn'
      }
    }
  }
})
